package com.dmtt.util;

import com.dmtt.web.common.Constant;
import com.dmtt.web.entity.User;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


public class BaseController {

    /**
     * 设置返回头TEXT_PLAIN
     * @param response
     * @return
     */
    public ResponseEntity<Response> backResponse(Response response,HttpStatus status){
    	HttpHeaders headers = new HttpHeaders();  
    	headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
		return new ResponseEntity<Response>(response, headers,status);
    
    }
    
    /**
     * 设置返回头TEXT_PLAIN
     * @param response
     * @return
     */
    public ResponseEntity<Response> backResponse(Response response){
    	HttpHeaders headers = new HttpHeaders();  
    	headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
		return new ResponseEntity<Response>(response, headers,HttpStatus.OK);
    }

    public User getUser(HttpServletRequest request){
        HttpSession session=request.getSession();
        return (User) session.getAttribute(Constant.SESSION_USER);
    }
    
    

}
